#ifndef __DBUtils__
#define __DBUtils__

#include "GlobalConfig.h"
#include <iostream>
#include "Poco/Runnable.h"
#include "dbstructure.h"
#include "command.h"

using namespace std;
using Poco::Runnable;
/*

*/

#define KI_LEN          sizeof(PProductKeyInfo)

class DBUtils
{
public:
    static bool CreateInstance(DBUtils*& pProductKey);
    static bool GenerateProductKey(time_t duration, int client_type);
    static bool IsProductKeyExist(string product_key);
    static bool IsUserExist(string username);
    static bool IsProductKeyExist(int key_id);

    static bool GetProductKeyInfoByKey(string product_key,db_keys* pKI);
    static bool GetProductKeyInfoByKeyID(int key_id, db_keys* pKI);
    static bool GetUserInfoByUsername(string username, db_user* pUser);
    static bool GetUserInfoByKeyID(int key_id, db_user* pUser);

    static bool Register(request_data* rd);
    static bool ChangePassword(const string user, const string new_pass);
    static bool UnBind(string user);

    static bool UpdateKeyStateWithKeyID(int key_id, int state);
    static bool UpdateKeyStateWithUser(string user, int state);
    static bool UpdateHardwareID(string user, string hardwareid);
    static bool UpdateUserKeyID(string user, int key_id);
    static bool CheckExpiration(db_keys* pKey);
private:
    DBUtils();
    ~DBUtils();
    static DBUtils* m_pSingleton;
};

#endif // __DBUtils__